import 'package:flutter/material.dart';

class Test002 extends StatefulWidget {
  const Test002({super.key});

  @override
  State<Test002> createState() => _Test002State();
}

class _Test002State extends State<Test002> {
  String s1 = "123456789";
  String s2 = "987654321";

  String text = "";

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text("动画2"),
      ),
      body: Center(
        child: Container(
          alignment: Alignment.center,
          height: 200,
          width: 300,
          color: Colors.red,
          child: AnimatedSwitcher(
            transitionBuilder: (Widget child, Animation<double> animation) {
              return FadeTransition(
                opacity: animation,
                child: ScaleTransition(
                  scale: animation,
                  child: child,
                ),
              );
            },
            duration: const Duration(seconds: 2),
            child: Text(
              text,
              key: UniqueKey(),
              style: const TextStyle(fontSize: 30),
            ),
          ),
        ),
      ),
      floatingActionButton: FloatingActionButton(
        child: const Icon(Icons.abc),
        onPressed: () {
          setState(() {
            if (text == s1) {
              text = s2;
            } else {
              text = s1;
            }
          });
        },
      ),
    );
  }
}
